package com.github.thinwonton.springboot.showcase.poi.apache;

import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.File;
import java.io.IOException;

public class ExportExcel {
    public static void main(String[] args) throws IOException {
        //创建excel文档
        HSSFWorkbook workbook = new HSSFWorkbook();
        workbook.createInformationProperties();

        /**
         * 获取文档信息，并配置
         */
        DocumentSummaryInformation dsi = workbook.getDocumentSummaryInformation();
        //文档类别
        dsi.setCategory("员工信息");
        //设置文档管理员
        dsi.setManager("江南");
        //设置组织
        dsi.setCompany("某集团");
        /**
         * 设置摘要信息
         */
        SummaryInformation si = workbook.getSummaryInformation();
        //设置文档主题
        si.setSubject("员工信息表");
        //设置文档标题
        si.setTitle("员工信息");
        //设置文档作者
        si.setAuthor("作者");
        //设置文档备注
        si.setComments("备注");


        //创建excel sheet
        HSSFSheet sheet = workbook.createSheet("员工信息表");

        //创建一行信息
        HSSFRow headerRow = sheet.createRow(0);

        //创建一个单元格
        HSSFCell cell = headerRow.createCell(0);
        cell.setCellValue("编号");

        //文件
        File parentFilePath = new File("d:/excel");
        if (!parentFilePath.exists()) {
            parentFilePath.mkdirs();
        }
        File file = new File(parentFilePath, "a.xls");

        workbook.write(file);

    }
}
